﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CampusSite.Filters;

namespace CampusSite
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

   

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            //filters.Add(new HandleErrorAttribute());
            filters.Add(new CustomHandleErrorAttribute());
            
            //con esta linea pedimos authorizacion para todo el sitio.
            //filters.Add(new AuthorizeAttribute());
            filters.Add(new CampusSite.Security.LogonAuthorize());

        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.IgnoreRoute("{*botdetect}", new { botdetect = @"(.*)BotDetectCaptcha\.ashx" });

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Inicio", id = UrlParameter.Optional} // Parameter defaults
            );


        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            //System.Data.Entity.Database.SetInitializer<CampusSite.Models.CampusSiteContext>(new CampusSiteInitializer());
            log4net.Config.XmlConfigurator.Configure();
           // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<CampusSite.Models.CampusSiteContext>());

            //Evita que EF valide la version del modelo de la base de datos con el modelo de entidades EF
            //http://www.yagoperez.com/modificando_base_de_datos_manualmente_con_entity_framework_code_first/

            System.Data.Entity.Database.SetInitializer<CampusSite.Models.CampusSiteContext>(null);
        }


    }
}